package org.jeecg.modules.professional.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.professional.entity.Professional;
import org.jeecg.modules.professional.service.ProfessionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *
 * @author liujiamiao
 * @since 2020-11-05
 */
@Validated
@RestController
@RequestMapping("/professional/professional")
@Api(tags = "专业技能")
public class ProfessionalController {

    @Autowired
    private ProfessionalService professionalService;

    @ApiOperation("分页查询")
    @GetMapping("/list/{page}/{size}/{basicId}")
    public Result list(@ApiParam("当前页数")@PathVariable("page") Integer page,
                       @ApiParam("每页显示几条数据")@PathVariable("size")Integer size,
                       @ApiParam("基本信息id")@PathVariable("basicId")Integer basicId){

        IPage<Professional> pageProfessional = professionalService.pageSelect(page,size,basicId);
        return Result.ok(pageProfessional);
    }

    @ApiOperation("根据id")
    @GetMapping("/info/{id}")
    public Result info(@ApiParam("id")@PathVariable("id")Integer id){
        Professional professional = professionalService.getById(id);
        return Result.ok(professional);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@ApiParam("id")@PathVariable("id")Integer id){
        boolean b = professionalService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("保存/更新")
    @PostMapping("/save")
    public Result save(@Valid @ApiParam("保存的json值")@RequestBody Professional professional){
        professionalService.saveOrUpdate(professional);
        return Result.ok();
    }
}